// FacebookInfiniteSession.cs
// Facebook/Framework/Service/Core
// Copyright (c) 2007, Nikhil Kothari. All Rights Reserved.
//

using System;
using System.Diagnostics;

namespace Facebook.Service.Core {

    /// <summary>
    /// Represents a Facebook "infinite" session that is used by a Facebook
    /// application that has been saved for extended use, i.e. until the user
    /// logs out of an application.
    /// </summary>
    internal sealed class FacebookInfiniteSession : FacebookSession {

        /// <summary>
        /// Creates an instance of a FacebookInfiniteSession with the
        /// specified application information and session key.
        /// </summary>
        /// <param name="appKey">The application key used as an API key.</param>
        /// <param name="secret">The application secret used to sign requests.</param>
        /// <param name="sessionKey">The previously saved infinite session key.</param>
        /// <param name="userID">The user ID associated with the saved session key. This is the page ID if the application is associated with a Page.</param>
        /// <param name="pageUserID">The user ID browsing the page if the session is associated with a page.</param>
        public FacebookInfiniteSession(string appKey, string secret, string sessionKey, string userID, string pageUserID)
            : base(appKey, secret) {
            if (String.IsNullOrEmpty(sessionKey)) {
                throw new ArgumentNullException("sessionKey");
            }
            if (String.IsNullOrEmpty(userID)) {
                throw new ArgumentNullException("userID");
            }

            FacebookSessionType sessionType = FacebookSessionType.User;
            if (String.IsNullOrEmpty(pageUserID) == false) {
                sessionType = FacebookSessionType.PresencePage;
            }

            InitializeSessionKey(sessionKey, /* sessionExpires */ false, sessionType);
            InitializeUserID(userID, pageUserID);
        }
    }
}
